package com.example.sys.async.handler;

import com.example.sys.async.po.SysASync;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

/***
 * 短信消息推送
 */
@Service
public class SmsASyncHandler extends AbstractASyncHandler {

    Logger logger  = LoggerFactory.getLogger(getClass());

    private ASyncHandler handler;

    @Value("${sms.service.class}")
    private String smsHandlerClass;

    public ASyncHandler getHandler() {
        if (this.handler == null){
            try {
                Class<?> clazz = Class.forName(this.smsHandlerClass);
                this.handler = (ASyncHandler) clazz.newInstance();
            }catch (Exception e){
                logger.warn("加载短信发送handler出错: " + e.getMessage());
            }
        }
        return this.handler;
    }

    @Override
    public SysASync handler(SysASync sysASync) {
        return getHandler().handler(sysASync);
    }
}
